//生产管理系统/数据趋势分析
import React, { Component } from 'react';
import { connect } from 'dva';
import { Card,Table} from 'antd';
import style from './EnvReal.less';
import {EnvRealGain} from '../../../services/redmoe';
import request from '../../../utils/request';
import PublicService from '../../../services/PublicService';
class EnvReal extends Component {
    state = {
      rowKey:1,
        columns:[{
            title: '指标名称',
            dataIndex: 'name',
            key: 'name',
            align:'center'
          }, {
            title: '一氧化碳',
            dataIndex: 'co',
            key: 'co',
            align:'center',
            render:(text,record,index) => <span onClick={this.save.bind(this,record,index,'co')}>{text?text:"/"}</span>
          }, {
            title: '颗粒物',
            dataIndex: 'pl',
            key: 'pl',
            align:'center',
            render:(text,record,index) => <span onClick={this.save.bind(this,record,index,'pl')}>{text?text:"/"}</span>
          }, {
            title: '氮氧化物',
            dataIndex: 'nox',
            key: 'nox',
            align:'center',
            render:(text,record,index) => <span onClick={this.save.bind(this,record,index,'nox')}>{text?text:"/"}</span>
          }, {
            title: '氯化氢',
            dataIndex: 'hcl',
            key: 'hcl',
            align:'center',
            render:(text,record,index) =><span onClick={this.save.bind(this,record,index,'hcl')}>{text?text:"/"}</span>
          }, {
            title: '水处理量',
            dataIndex: 'waterTreatment',
            key: 'waterTreatment',
            align:'center',
            render:(text,record,index) => <span onClick={this.save.bind(this,record,index,'waterTreatment')}>{text?text:"/"}</span>
          }, {
            title: 'COD',
            dataIndex: 'cod',
            key: 'cod',
            align:'center',
            render:(text,record,index) => <span onClick={this.save.bind(this,record,index,'cod')}>{text?text:"/"}</span>
          }, {
            title: 'pH值',
            dataIndex: 'ph',
            key: 'ph',
            align:'center',
            render:(text,record,index) => <span onClick={this.save.bind(this,record,index,'ph')}>{text?text:"/"}</span>
          }
        ],
        data:[{
           
            name: '指标单位',
            co:"mg/m³",
            pl:"mg/m³",
            nox:"mg/m³",
            hcl:"mg/m³",
            waterTreatment:"m³",
            cod:"mg/L",
            ph:"/",
            rowKey:"1"

          }, {
            name: '实时值',
            rowKey:"2"

          },{
            name: '小时均值',
            rowKey:"3"
          },{
            name: '排放限值',
            ph:"/",
            rowKey:"4"
          },
        ],
        obj:{}
    };
    //页面进入事件

    componentDidMount () {
        request(`/hh-management-web/gnhj/environmentalindicat/getNewData`).then(data => {
            console.log(data)
            this.setState({
                obj:data.data.ret
            })
         
          
         console.log(this.state.data)
        })
    }

    // 点击事件
    save = (record,index,a) => {
  if(record.rowKey == '2'){
    this.props.history.push("/controlSubject/EnvironmentalHistory/EnvTrend")
    PublicService.setCookie('Kind', a);
  }
      
      
        console.log(record,index,a)
      
    }

    render() {
        const {obj} = this.state
        var arr = this.state.data
        arr[1]={...arr[1],...obj.newValue}
        arr[2]={...arr[2],...obj.averageValue}
        arr[3]={...arr[3],...obj.hoursValue}
        return (
            <div className={style.myTable}>

                        <Card
                            className={style.CardBottom}
                        >
                        <Table
                            ref="table"

                            style={{width:this.state.repairWidth,margin:0}}
                        
                           
                            columns={this.state.columns}
                            dataSource={this.state.data}
                            align="center"
                            className={style.Table}
                            bordered={true}
                            pagination={false}
                            size="small"
                        />
                 
                   

                        </Card>
                        </div>
                   
             

        )
    }
}

export default connect()(EnvReal)